package com.usian.user.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.user.ApUserFollowControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.user.dtos.UserRelationDto;
import com.usian.model.user.pojos.ApUserFollow;
import com.usian.user.service.ApUserFollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class ApUserFollowController implements ApUserFollowControllerApi {

    @Autowired
    private ApUserFollowService apUserFollowServiceI;

    @PostMapping("user_follow")
    @Override
    public ResponseResult follow(@RequestBody UserRelationDto dto) {
        return apUserFollowServiceI.follow(dto);
    }

    @Override
    @GetMapping("one")
    public ApUserFollow queryApUserFollowByUserIdAndFollowId(
            @RequestParam Integer userId, @RequestParam Integer followId) {
        LambdaQueryWrapper<ApUserFollow> followLambdaQueryWrapper =
                Wrappers.<ApUserFollow>lambdaQuery().eq(ApUserFollow::getUserId, userId).eq(ApUserFollow::getFollowId, followId);

        return apUserFollowServiceI.getOne(followLambdaQueryWrapper);
    }
}
